package com.tkc.common.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 
 * @Function: 随机获取字符串工具类
 * 
 * @Project :assessmenttask 
 * @Package :com.tkc.common.util 
 * @File :RandomUtil.java 
 * @ClassName: RandomUtil  
 * 
 * @author tankaichao 
 * @email cgztkc@126.com 
 * @Date 2016年8月9日下午7:07:00
 * @since JDK 1.8 
 *
 */
public class RandomUtil {
	
	/**
	 * 随机获取n个数字字符串
	 * @param n
	 * @return
	 */
	public static String getNumberRandom(int n){
		String returnValue = "";
		for (int i = 0; i < n; i++) {
			int random = (int)(Math.random()*10);
			returnValue += random;
		}
		return returnValue;
	}
	
	/**
	 * 随机获取n个字母字符串
	 * @param n
	 * @return
	 */
	public static String getLetterRandom(){
		
		String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		int presenttime = TimeHelperUtil.transformpresenttime();
		String str="" + presenttime;
		List<String> list = new ArrayList<String>();
		String[] split = str.split("");
		Collections.addAll(list, split);
		for (int i = 0; i < split.length; i++) {
			int rand = (int) (Math.random() * letters.length()); 
			String letter = String.valueOf(letters.charAt(rand));
    		int location = (int) (Math.random() * list.size()); 
    		list.add(location,letter);
		}
    	
		String returnValue = "";
		for (int i = 0; i < list.size(); i++) {
			returnValue +=list.get(i);
    	}
		
		return returnValue;
	}
}
